package com.vpen.picupload.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * -@Version 1.0
 * -@Author:Vpen
 * -@Date:2021/8/1 21:52
 * -@Content: 静态资源映射
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 虚拟映射
     * */
    @Value("${file.staticAccessPath}")
    private  String staticAccessPath;
    /**
    * 图片实际位置
    * */
    @Value("${file.uploadFolder}")
    private String uploadFolder;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
         * 配置资源映射
         * 意思是：如果访问的资源路径是以staticAccessPath开头的，
         * 就给我映射到本机的uploadFolder这个文件夹内，去找你要的资源
         */
         registry.addResourceHandler(staticAccessPath)
        .addResourceLocations("file:"+uploadFolder);
    }
}
